#ifndef FIELDITEM_H
#define FIELDITEM_H
#include <QObject>
#include "utils.h"
#include "format/format.h"
#include "utils/buffer.h"

class FieldItem : public QObject
{
    Q_OBJECT

public:
    explicit FieldItem(Format *format,
                      FEFieldNode *node,
                       FieldItem* parent = nullptr);
    ~FieldItem();

    void appendChild(FieldItem* child);

    FieldItem* child(int row);

    int childCount() const;

    int columnCount() const;

    QVariant data(int column) const;

    int row() const;

    FieldItem* parent();

    FERange range();

private:
    void dessect();
    void constructChildren(FEList *nodes, uint8_t depth);
    QString getDisplayMask() const;
    QString getDisplayName() const;
    QString getDisplayValue() const;

    Format *format_{nullptr};
    FieldItem* parent_{nullptr};
    FieldItem* pre_{nullptr};
    FieldItem* next_{nullptr};
    QList<FieldItem*> children_;

    FEFieldNode node_;
    bool atom_{false};

    FEBuffer *mem_buffer_{nullptr};
};

#endif // FIELDITEM_H
